import 'package:flutter/material.dart';
import 'package:my_flutter_github/page/MineTabPage.dart';
import 'package:my_flutter_github/page/TrendTabPage.dart';
import 'package:my_flutter_github/page/DynamicTabPage.dart';
import 'package:my_flutter_github/utils/NavigatorUtils.dart';
import 'package:my_flutter_github/widgets/HomeDrawer.dart';
import 'dart:async';

import 'package:my_flutter_github/MyStyle.dart';
import 'package:my_flutter_github/widgets/TabBarWidget.dart';
import 'package:my_flutter_github/widgets/TitleBarWidget.dart';



class HomePage extends StatelessWidget {
  static const sName = "/HOME";

  //显示退出Dialog
  Future<bool> _showExitDialog(BuildContext context) {
    return showDialog(
        context: context,
        builder: (context) {
          return new AlertDialog(
            title: new Text("提示"),
            content: new Text("退出程序?"),
            actions: <Widget>[
              new FlatButton(
                  onPressed: () {
                    Navigator.of(context).pop(false);
                  },
                  child: new Text("取消")),
              new FlatButton(
                  onPressed: () {
                    Navigator.of(context).pop(true);
                  },
                  child: new Text("确定")),
            ],
          );
        });
  }

  _createTab(icon, text) {
    return new Tab(
      child: new Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          new Icon(icon, size: 16.0),
          new Text(text),
        ],
      ),
    );
  }

  _createPage() {
    return [
      new DynamicTabPage(),
      new TrendTabPage(),
      new MineTabPage(),
    ];
  }

  @override
  Widget build(BuildContext context) {
    List<Widget> tabs = [
      _createTab(MyIcons.MAIN_DT, "动态"),
      _createTab(MyIcons.MAIN_QS, "趋势"),
      _createTab(MyIcons.MAIN_MY, "我的"),
    ];

    return WillPopScope(
      onWillPop: () {
        return _showExitDialog(context);
      },
      child: new TabBarWidget(
        drawer: new HomeDrawer(),
        type: TabBarWidget.TAB_BOTTOM,
        tabItems: tabs,
        tabViews: _createPage(),
        backgroundColor: MyColors.primarySwatch,
        indicatorColor: Colors.white,
        title: new TitleBarWidget(
          title: "MyFlutterApp",
          iconData: MyIcons.MAIN_SEARCH,
          needRightLocalIcon: true,
          onPressed: (){
            //to search page
            NavigatorUtils.goSearchPage(context);
          },
        ),
      ),
    );
  }

}
